#!/bin/bash
function shell_run() {
    dockerMap=$1
    if [ "${#dockerMap[@]}" -eq 0 ]; then
          echo ""
    else
      # 添加其他 Docker 参数
      for element in "${dockerMap[@]}"; do
          echo ${element}
          eval ${element}
      done
    fi
}

function main() {
    dockerName=bladex/sentinel-dashboard
    dockerNameDir=/bladex/sentinel
    version=1.8.0
    dockerAllName=${dockerName}":"${version}
    asName=sentinel
    port=8858
    networkName="common-network"
    allDir=/docker-volumes/${asName}/${port}

    rmOp="rm -r ${allDir}"
    mkdirOp="mkdir -p ${allDir}"
    dockerPull="docker pull ${dockerAllName}"
    dockerRm="docker rm -f ${asName}"
    dockerOne="docker run --name ${asName} \
     --network=${networkName} \
     -p ${port}:8858 \
     --privileged=true \
     -d ${dockerAllName}"

    dockerCp="docker cp ${asName}:${dockerNameDir} ${allDir}"

    dockerTwo="docker run --name ${asName} \
     --network=${networkName} \
     -p ${port}:8858 \
     -v ${allDir}:${dockerNameDir} \
     --privileged=true \
     -d ${dockerAllName}"

     dockerMap=("${dockerRm}")
     dockerMap+=("${rmOp}")
     dockerMap+=("${mkdir}")
     dockerMap+=("${dockerPull}")
     dockerMap+=("${dockerOne}")
     dockerMap+=("${dockerCp}")
     dockerMap+=("${dockerRm}")
     dockerMap+=("${dockerTwo}")

     shell_run "${dockerMap[@]}"

    #if [ "${#dockerMap[@]}" -eq 0 ]; then
    #      echo ""
    #else
      # 添加其他 Docker 参数
      #for element in "${dockerMap[@]}"; do
      #    echo ${element}
      #    eval ${element}
      #done
    #fi

    #echo ${dockerRm}
    #eval ${dockerRm}
    #echo ${rmOp}
    #eval ${rmOp}
    #echo ${mkdir}
    #eval ${mkdir}

    #echo ${dockerPull}
    #eval ${dockerPull}
    #echo ${dockerOne}
    #eval ${dockerOne}

    #echo ${dockerCp}
    #eval ${dockerCp}
    #echo ${dockerRm}
    #eval ${dockerRm}
    #echo ${dockerTwo}
    #eval ${dockerTwo}
}

main


#docker run --name sentinel \
#-p 8858:8858 \
#--privileged=true \
#--restart=always \
#-v /etc/localtime:/etc/localtime \
#-d bladex/sentinel-dashboard:1.8.0
#echo "cp"
#docker cp sentinel:/bladex /docker-volumes/sentinel/8858/bladex
#docker rm -f sentinel
#echo "run"
#docker run --name sentinel \
#-p 8858:8858 \
#--privileged=true \
#--restart=always \
#-v /etc/localtime:/etc/localtime \
#-v /docker-volumes/sentinel/8858/bladex/sentinel:/bladex/sentinel \
#-d bladex/sentinel-dashboard:1.8.0
#echo "ok"
#docker logs -f -n 200 sentinel